package com.jader.adapter;

import java.util.List;
import com.jader.beans.Goods;
import com.jader.util.JaderApplication;
import com.zlp.jader.R;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class MerchantAdapter extends BaseAdapter {

	private List<Goods> list;
	private Context context;
	private LayoutInflater mInflater;
	private ViewHolder viewHolder;

	public MerchantAdapter(List<Goods> list, Context context) {
		super();
		this.list = list;
		this.context = context;
		mInflater = LayoutInflater.from(this.context);
	}

	@Override
	public int getCount() {
		return list.size();
	}

	@Override
	public Object getItem(int arg0) {
		return list.get(arg0);
	}

	@Override
	public long getItemId(int arg0) {
		return arg0;
	}

	@Override
	public View getView(int arg0, View arg1, ViewGroup arg2) {
		if (arg1 == null) {
			arg1 = mInflater.inflate(R.layout.adapter_listview_merchant, null);
			viewHolder = new ViewHolder();
			viewHolder.dersTextView = (TextView) arg1
					.findViewById(R.id.merchant_ders);
			viewHolder.imageView = (ImageView) arg1
					.findViewById(R.id.merchant_adapter_list_pic);
			viewHolder.titleTextView = (TextView) arg1
					.findViewById(R.id.merchant_title);
			viewHolder.priceTextView = (TextView) arg1
					.findViewById(R.id.specific_price);
			arg1.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) arg1.getTag();
		}
		JaderApplication.getBitmapUtils().display(viewHolder.imageView,
				JaderApplication.getIP()+"/Jader"+ list.get(arg0).getPicture());
		viewHolder.dersTextView.setText(list.get(arg0).getDesc());
		viewHolder.titleTextView.setText(list.get(arg0).getGoodsName());
		viewHolder.priceTextView.setText("价格： ￥" + list.get(arg0).getPrice());
		return arg1;
	}

	class ViewHolder {
		ImageView imageView;
		TextView titleTextView;
		TextView dersTextView;
		TextView priceTextView;
	}

}
